<template>
  <div class="mobile-search-box">
    <el-card class="search-card">
      <el-form :model="data" size="small" class="search-form">
        <el-form-item label="支付号" class="search-item">
          <el-input v-model="data.outTradeNo" placeholder="请输入支付号" clearable class="search-input" />
        </el-form-item>

        <el-form-item label="订单号" class="search-item">
          <el-input v-model="data.uuid" placeholder="请输入订单号" clearable class="search-input" />
        </el-form-item>
        <el-form-item label="查询时间" class="search-item">
          <el-date-picker v-model="data.selectedDate" type="date" placeholder="请选择日期" value-format="timestamp"
            @change="handleDateChange" />
        </el-form-item>

        <el-form-item class="search-button-item">
          <el-button type="primary" icon="el-icon-search" @click="onSubmit" class="search-button" :loading="loading">
            搜索
          </el-button>
          <el-button icon="el-icon-refresh" @click="onReset" class="reset-button">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'MobileSearchBox',
  props: {
    data: {
      type: Object,
      default() {
        return {
          outTradeNo: null,
          uuid: null,
          selectedDate: null,
          timeRange: []
        }
      }
    },
    loading: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    onSubmit() {
      this.$emit('search')
    },

    onReset() {
      this.$emit('reset')
    },

    handleDateChange(date) {
      if (date) {
        // 将选择的日期转换为当天0点和23:59:59的时间戳
        const startOfDay = new Date(date)

        startOfDay.setMinutes(0, 0, 0, 0)
        const endOfDay = new Date(date)
        endOfDay.setHours(23, 59, 59, 999)

        this.data.timeRange = [startOfDay.getTime(), endOfDay.getTime()]
      } else {
        this.data.timeRange = []
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.mobile-search-box {
  margin-bottom: 10px;
}

.search-card {
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.search-form {
  .search-item {
    margin-bottom: 15px;

    ::v-deep .el-form-item__label {
      font-weight: 500;
      color: #333;
      width: 80px !important;
      text-align: left;
    }

    ::v-deep .el-form-item__content {
      margin-left: 80px !important;
    }
  }

  .search-button-item {
    margin-bottom: 0;
    text-align: center;

    ::v-deep .el-form-item__content {
      margin-left: 0 !important;
    }
  }
}

.search-input {
  ::v-deep .el-input__inner {
    border-radius: 6px;
    border: 1px solid #dcdfe6;
    font-size: 14px;

    &:focus {
      border-color: #409eff;
      box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
    }
  }
}

.search-button {
  width: 80px;
  height: 36px;
  border-radius: 6px;
  font-size: 14px;
  margin-right: 10px;
}

.reset-button {
  width: 80px;
  height: 36px;
  border-radius: 6px;
  font-size: 14px;
}

// 移动端优化
@media (max-width: 768px) {
  .search-form {
    .search-item {
      ::v-deep .el-form-item__label {
        width: 70px !important;
        font-size: 13px;
      }

      ::v-deep .el-form-item__content {
        margin-left: 70px !important;
      }
    }
  }

  .search-input {
    ::v-deep .el-input__inner {
      font-size: 13px;
      height: 36px;
    }
  }

  .search-button,
  .reset-button {
    width: 70px;
    height: 32px;
    font-size: 13px;
  }
}
</style>
